package com.zhao.controller.admin;

import com.zhao.pojo.Announcement;
import com.zhao.pojo.Feedback;
import com.zhao.pojo.result.Response;
import com.zhao.pojo.result.ResponseResult;
import com.zhao.service.FeedbackService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Objects;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author : Mr.zhao
 * @Date: 2022/05/02/11:49
 * @Description:
 */
@Controller
@RequestMapping("/feedback")
public class FeedbackController {
    @Autowired
    FeedbackService feedbackService;

    @ResponseBody
    @RequestMapping("/updateFeedback")
    public ResponseResult<Feedback> updateAnnouncement(Feedback feedback){
        if (Objects.isNull(feedback)){
            return Response.makeErrRsp("数据异常");
        }else if (Objects.isNull(feedback.getId())){
            if (Strings.isBlank(feedback.getContent())&&Strings.isBlank(feedback.getName())&&Strings.isBlank(feedback.getEmail())) {
                return Response.makeErrRsp("请填写");
            }
        }
        if (!feedbackService.saveOrUpdate(feedback)) {
            return Response.makeErrRsp("失败");
        }
        return Response.makeOKRsp(feedback);
    }
}
